package com.gavin.algorithm.sort;

import java.util.Arrays;


/**
 * 冒泡排序
 * @author lenovo
 *
 */
public class BubbleSort {

	public static void main(String[] args) {
		int[] a = { 26, 53, 67, 48, 57, 13, 48, 32, 60, 50 };
		bubbleSort(a);
		System.out.println(Arrays.toString(a));
	}

	private static void bubbleSort(int[] array) {
		int i, j, temp, count1 = 0, count2 = 0;
		boolean flag=true;
		for (i = 0; (i < array.length - 1)&&flag; i++) {
			flag=false;
			for (j = 0; j < array.length - i - 1; j++) {
				count1++;
				if (array[j] > array[j + 1]) {
					count2++;
					temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
					flag=true;
				}
			}
		}
		System.out.println("总共进行了"+count1+"次比较,"+count2+"次交换");

	}

}
